/*
 * @Author: 张小平
 * @Date:   2025-05-01
 * @Email:  qqshuqian@163.com
 * @Copyright © 2024 aseyun. All rights reserved.
 */

/**
 *
 * @param {校验数据源名} rule
 * @param {*} value
 * @param {*} callback
 */
var validateDsName = (rule, value, callback) => {
  var re = /(?=.*[a-z])(?=.*_)/;
  if (value && (!(re).test(value))) {
    callback(new Error('数据源名称不合法, 组名_数据源名形式'))
  } else {
    callback()
  }
}

export const tableOption = {
  border: true,
  index: true,
  indexLabel: '#',
  stripe: true,
  menuAlign: 'center',
  align: 'center',
  viewBtn: true,
  searchEnter: true,
  grid: window.isMobile,
  gridSpan: 24,
  column: [
    {
      label: '主键',
      prop: 'id',
      hide: true,
      addDisplay: false,
      editDisplay: false
    },
    {
      label: '数据库名',
      prop: 'title',
      search: true,
      rules: [
        {required: true, message: '请输入数据库标题', trigger: 'blur'},
        {max: 32, message: '长度在 32 个字符', trigger: 'blur'}
      ]
    },
    {
      label: '别名',
      prop: 'name',
      search: true,
      sortable: "custom",
      rules: [
        {required: true, message: '请输入数据库别名', trigger: 'blur'},
        {max: 32, message: '长度在 32 个字符', trigger: 'blur'},
        {validator: validateDsName, trigger: 'blur'}
      ]
    },
    {
      label: '配置方式',
      prop: 'confType',
      type: 'radio',
      value: 0,
      border: true,
      rules: [
        {required: true, message: '请选择配置方式', trigger: 'blur'}
      ],
      dicData: [{
        label: '主机',
        value: 0
      }, {
        label: 'JDBC',
        value: 1
      }]
    },
    {
      label: '数据库',
      hide: true,
      prop: 'dbName',
      search: true,
      rules: [
        {required: true, message: '请输入数据库名称', trigger: 'blur'},
        {max: 32, message: '长度在 32 个字符', trigger: 'blur'}
      ]
    },
    {
      label: '类型',
      prop: 'dbType',
      type: 'select',
      rules: [
        {required: true, message: '请选择数据库类型', trigger: 'blur'}
      ],
      dicData: [{
        label: 'MySQL',
        value: 'mysql'
      }
        // , {
        //   label: 'PostgreSQL',
        //   value: 'pg'
        // }, {
        //   label: 'Oracle',
        //   value: 'oracle'
        // }, {
        //   label: 'IBM DB2',
        //   value: 'db2'
        // }
      ]
    },
    {
      label: '用户名',
      prop: 'username',
      rules: [
        {required: true, message: '请输入用户名', trigger: 'blur'},
        {max: 32, message: '长度在 32 个字符', trigger: 'blur'}
      ]
    },
    {
      label: '密码',
      prop: 'password',
      hide: true,
      overHidden: true,
      rules: [
        {required: true, message: '请输入密码', trigger: 'blur'},
        {max: 100, message: '长度在 100 个字符', trigger: 'blur'}
      ]
    },

    {
      label: 'jdbcUrl',
      prop: 'url',
      type: 'textarea',
      span: 24,
      addDisplay: true,
      editDisplay: true,
      row: true,
      minRows: 2,
      hide: true,
      overHidden: true,
      rules: [
        {required: true, message: '请输入jdbcUrl', trigger: 'blur'}
      ]
    },
    {
      label: '主机',
      prop: 'host',
      hide: true,
      rules: [
        {required: true, message: '请输入主机 IP', trigger: 'blur'},
        {max: 100, message: '长度在 100 个字符', trigger: 'blur'}
      ]
    },
    {
      label: '端口',
      prop: 'port',
      type: 'number',
      maxRows: 65535,
      hide: true,
      rules: [
        {required: true, message: '请输入端口', trigger: 'blur'}
      ]
    },

    {
      width: 150,
      type: 'datetime',
      label: '更新时间',
      prop: 'updateTime',
      format: 'yyyy-MM-dd HH:mm:ss',
      valueFormat: 'yyyy-MM-dd HH:mm:ss',
      display: false,
      hide: false
    }
  ]
}
